package day08;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class Demo02 {

	public static void main(String[] args) throws Exception {
		Person p1=new Person("范传奇",35,"男");
		Person p2=new Person("李红和",25,"男");
		String file="abc/obj.dat";
		p1.firend=p2;
		

		FileOutputStream fos=new FileOutputStream(file);
		BufferedOutputStream bos=new BufferedOutputStream(fos);
		ObjectOutputStream oos=new ObjectOutputStream(bos);

		
		oos.writeObject(p1);
		oos.writeObject(p2);
		
		oos.close();
		
		
		FileInputStream fis = new FileInputStream(file);
		BufferedInputStream bis = new BufferedInputStream(fis);
		ObjectInputStream ois = new ObjectInputStream(bis);
	
		
//		Person p;
//		while(){
//			
//			p=(Person)ois.readObject();
//			System.out.println(p);
//		}//错误！
		
		
		Person p11=(Person)ois.readObject();
		Person p22=(Person)ois.readObject();
		System.out.println(p11);
		System.out.println(p22);
		
		
		ois.close();
	}

}
